package inabit.data.expression.arithmetic;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import inabit.base.WorkingMemory;
/**@author Rafael Rocha*/
public class NegativeExpression implements ArithmeticExpression{

	private ArithmeticExpression inside;
	
	public NegativeExpression(ArithmeticExpression inside) {
		this.inside = inside;
	}
	
	@Override
	public String getResult(WorkingMemory wm) {
		String result = inside.getResult(wm);
		if(result == null) return null;
		return Double.toString(0 - Double.parseDouble(result));
	}

	@Override
	public String stringForm() {
		String insideStr = inside.stringForm();
		if(!inside.isLeaf()) {insideStr = "( " + insideStr + " )";}
		return "-" + insideStr;
	}

	@Override
	public Collection<String> getReferenced() {
		List<String> all = new ArrayList<String>();
		
		all.addAll(inside.getReferenced());
		return all;
	}

	@Override
	public boolean isLeaf() {
		return true;
	}
}
